package com.zyj.myapplication.Adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Parcelable;
import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zyj.myapplication.Activity.ClubInfoActivity;
import com.zyj.myapplication.Activity.ShaituInfoActivity;
import com.zyj.myapplication.Javabean.Club;
import com.zyj.myapplication.Javabean.Shaitu;
import com.zyj.myapplication.Model.Constant;
import com.zyj.myapplication.R;

import java.util.List;

import it.sephiroth.android.library.picasso.Picasso;

/**
 * Created by Administrator on 2017/10/18.
 */

public class ShaituListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private List mDataList;
    private LayoutInflater mLayoutInflater;

    public ShaituListAdapter(Context mContext, List mDataList) {
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_shaitulist, parent, false);
        return new ShaituListAdapter.ViewHolder(v);

    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Shaitu entity = (Shaitu) mDataList.get(position);
        if (null == entity)
            return;
        ShaituListAdapter.ViewHolder viewHolder = (ShaituListAdapter.ViewHolder) holder;
        if (entity.getShaier() == null) {
            viewHolder.user_name.setText("周艳军");
            viewHolder.user_pic.setImageResource(R.drawable.tx);
        } else {
            viewHolder.user_name.setText(entity.getShaier().getUser_name());
            Picasso.with(mContext).
                    load(Constant.PIC_URL + entity.getShaier().getPhoto())
                    .placeholder(R.drawable.tx).noFade().into(viewHolder.user_pic);
        }
        viewHolder.item_shaitutext.setText("#" + entity.getClub_name() + "#");
        viewHolder.item_shaituhit.setText(entity.getHits());
        viewHolder.item_shaituintroduction.setText(entity.getTitle());
        //  viewHolder.item_shaituintroduction.setText((CharSequence) entity.getComment());
        Picasso.with(mContext).
                load(Constant.PIC_URL + entity.getThumb0()).into(viewHolder.item_shaitupic);

        /*做一个页面跳转*/
        final String Suser_Time = entity.getUpdate_time();
        final String Suser_address = "http://172.24.10.175/workout/Uploads/" + entity.getThumb0();
        final String Suser_address1 = "http://172.24.10.175/workout/Uploads/" + entity.getThumb1();
        final String Suser_address2 = "http://172.24.10.175/workout/Uploads/" + entity.getThumb2();
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(mContext, ShaituInfoActivity.class);
                intent.putExtra("shaituid", entity.getId());
    //            intent.putExtra("username", entity.getShaier().getUser_name());
   //             intent.putExtra("userpic", "http://172.24.10.175/workout/Uploads/" + entity.getShaier().getPhoto());
   //             intent.putExtra("Suser_Time", Suser_Time);
   //             intent.putExtra("Suser_address", Suser_address);
                intent.putExtra("Suser_address1", Suser_address1);
                intent.putExtra("Suser_address2", Suser_address2);
                intent.putExtra("clubname", entity.getClub_name());
   //             intent.putExtra("comment",entity.getTitle());
                mContext.startActivity(intent);
            }
        });

    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        ImageView user_pic, item_shaitupic, imageView;
        TextView user_name, item_shaitutext, item_shaituhit, item_shaituintroduction;


        public ViewHolder(View itemView) {
            super(itemView);
            user_pic = (ImageView) itemView.findViewById(R.id.user_pic);
            item_shaitupic = (ImageView) itemView.findViewById(R.id.item_shaitupic);
            imageView = (ImageView) itemView.findViewById(R.id.imageView);
            user_name = (TextView) itemView.findViewById(R.id.user_name);
            item_shaitutext = (TextView) itemView.findViewById(R.id.item_shaitutext);
            item_shaituhit = (TextView) itemView.findViewById(R.id.item_shaituhit);
            item_shaituintroduction = (TextView) itemView.findViewById(R.id.item_shaituintroduction);
        }
    }

}

